//
//  erViewController.m
//  豆瓣
//
//  Created by hy on 15/12/31.
//  Copyright © 2015年 hongyu. All rights reserved.
//

#import "erViewController.h"
#import "UIImageView+WebCache.h"
#import "hydateBaseHandle.h"
#import "HdModel.h"
@interface erViewController ()

@end

@implementation erViewController

- (instancetype)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        
    }
    return self;
}
- (void)dealloc {
    [_dic release];
    [super dealloc];
}
- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.view.backgroundColor = [UIColor whiteColor];
    self.navigationItem.title = self.dic[@"title"];
    UIBarButtonItem *item = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"sc.png"] style:UIBarButtonItemStylePlain target:self action:@selector(itemAction:)];
//    设置颜色
    self.navigationController.navigationBar.tintColor = [UIColor whiteColor];
    self.navigationItem.rightBarButtonItem = item;
    [item release];
    
    UIScrollView *scroll = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)];
    [self.view addSubview:scroll];
    scroll.contentSize = CGSizeMake(0, self.view.frame.size.height * 2.5);
    
    UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(20, 20, 200, 30)];
    label.text = self.dic[@"title"];
    [scroll addSubview:label];
    [label release];
    
    UIImageView *image = [[UIImageView alloc] initWithFrame:CGRectMake(20, 60, 130, 200)];
    [image sd_setImageWithURL:[NSURL URLWithString:self.dic[@"image"]]];
    [scroll addSubview:image];
    [image release];

//    时间图标和时间
    UIImageView *image1 = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"icon_date_blue.png"]];
    image1.frame = CGRectMake(155, 60, 25, 25);
    [scroll addSubview:image1];
    [image1 release];
    UILabel *date = [[UILabel alloc] initWithFrame:CGRectMake(180, 58, 190, 30)];
    NSString *str1 = [self.dic[@"begin_time"] substringWithRange:NSMakeRange(5, 11)];
    NSString *str2 = [self.dic[@"end_time"] substringWithRange:NSMakeRange(5, 11)];
    date.text = [NSString stringWithFormat:@"%@ -- %@", str1, str2];
    date.font = [UIFont systemFontOfSize:15];
    [scroll addSubview:date];
    [date release];
    
// 北京啥啥啥
    UIImageView *image2 = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"icon_sponsor_blue@2x.png"]];
    image2.frame = CGRectMake(155, 90, 25, 25);
    [scroll addSubview:image2];
    [image2 release];
    UILabel *name = [[UILabel alloc] initWithFrame:CGRectMake(180, 88, 190, 30)];
    name.text = self.dic[@"owner"][@"name"];
    [scroll addSubview:name];
    [name release];

    UIImageView *image3 = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"icon_catalog_blue@2x.png"]];
    image3.frame = CGRectMake(155, 120, 25, 25);
    [scroll addSubview:image3];
    [image3 release];
    UILabel *catalog = [[UILabel alloc] initWithFrame:CGRectMake(180, 118, 190, 30)];
    catalog.text = self.dic[@"category_name"];
    [scroll addSubview:catalog];
    [catalog release];
    
    
    UIImageView *image4 = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"icon_spot_blue@2x.png"]];
    image4.frame = CGRectMake(155, 150, 25, 25);
    [scroll addSubview:image4];
    [image4 release];
    UILabel *address = [[UILabel alloc] initWithFrame:CGRectMake(180, 148, 190, 70)];
    address.text = self.dic[@"address"];
    address.numberOfLines = 3;
    [scroll addSubview:address];
    [address release];
    
//    标题
    UILabel *activity = [[UILabel alloc] initWithFrame:CGRectMake(20, 270, 100, 30)];
    activity.text = @"活动介绍";
    activity.font = [UIFont boldSystemFontOfSize:20];
    [scroll addSubview:activity];
    [activity release];
    
    
//    设置介绍内容
    
//    UILabel *angel = [[UILabel alloc] init];
//    NSDictionary *dic = [NSDictionary dictionaryWithObjectsAndKeys:[UIFont systemFontOfSize:17], NSFontAttributeName, nil];
//    CGRect rect = [angel.text boundingRectWithSize:CGSizeMake(200, 500) options:NSStringDrawingUsesLineFragmentOrigin attributes:dic context:nil];
//    angel.frame = CGRectMake(20, 310, 355, rect.size.height);
//    angel.numberOfLines = 100;
//    angel.text = self.dic[@"content"];
//    [scroll addSubview:angel];
//    [angel release];
    
// 
    UILabel *angel = [[UILabel alloc] initWithFrame:CGRectMake(20, 310, 355, self.view.frame.size.height * 2.5 - 300)];
    angel.backgroundColor = [UIColor whiteColor];
    angel.text = self.dic[@"content"];
    NSLog(@"%@", self.dic[@"content"]);
    angel.numberOfLines = 60;
    [scroll addSubview:angel];
    [angel release];
    

    
    

    
}
- (void)itemAction:(UIBarButtonItem *)item {
    NSArray *arr = [[hydateBaseHandle shareDataBaseHandle] selectDate];
    NSMutableArray *arr1 = [NSMutableArray array];
    for (HdModel *model in arr) {
        NSString *str = model.title;
        [arr1 addObject:str];
    }
    if (![arr1 containsObject:_dic[@"title"]]) {
        //    创建警报对话框
        UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"提示" message:@"收藏成功" preferredStyle:UIAlertControllerStyleAlert];
        //    创建警报方法
        UIAlertAction *action = [UIAlertAction actionWithTitle:@"确认" style:UIAlertActionStyleDefault handler:nil];
        [alert addAction:action];
        [self presentViewController:alert animated:YES completion:nil];
        [self.Array addObject:_dic];
        [[hydateBaseHandle shareDataBaseHandle] insertModel:self.dic[@"title"]];
        
    }
    else if ([arr1 containsObject:_dic[@"title"]]) {
//        [self.delegate chuan:self.Array];
        UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"提示" message:@"活动已收藏" preferredStyle:UIAlertControllerStyleAlert];
            
            UIAlertAction *action = [UIAlertAction actionWithTitle:@"确认" style:UIAlertActionStyleDefault handler:nil];
            [alert addAction:action];
            [self presentViewController:alert animated:YES completion:nil];
    }
    
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
